<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
 <title>微信扫码登录</title>
  <script type="text/javascript" th:src="@{http://192.168.3.128:8084/js/jquery.min.js}"></script>

 </head>
<body>
<div  id="ma">
<img alt="" src="" id="image" />
</div>
<script type="application/javascript">
var test = 0;
/*     $(function(){
        $.post("http://192.168.3.128:8084/index/weixin",function(data){
            var ma = data.shorturl;
            var srcMa = "http://qr.topscan.com/api.php?text="+ma;
            var imgg = "<img class='h-img' alt='' src="+srcMa+"></img>";
            //将生成的二维码放到div里
            $("#ma").empty().append(imgg);
        });
        //置初始值
        $.post("http://192.168.3.128:8084/index/type",{"a":0});
        panduan();
    }) */
        $(function(){
        	$.ajax({
        		type : 'POST',
        		url : "/index/weixin",
        		dataType:'json',
        		data:{

        		},
        		success : function(data) {
        			var ma = data.shorturl;
                    var srcMa = "http://qr.topscan.com/api.php?text="+ma;
                    
                    $('#image').attr('src',srcMa);
                    
                    console.log(srcMa);
                    
                 /*    var imgg = '<img alt='' src='+srcMa+'></img>';
                    //将生成的二维码放到div里
                    $("#ma").empty().append(imgg);
 */        		},
        		error:function(data) {
        			console.log(data);
        		}
        	});
        //置初始值
        $.post("http://192.168.3.128:8084/index/type",{"a":0});
        panduan();
    })
    //微信扫码是否成功的判断
    var test = 0;
    function panduan(){
        $.post("http://192.168.3.128:8084/index/successDL",function(data){
        	
        
            if(data.type==1){
            	
            	//alert(data.type);
            	
            	var  userId = data.userId;

                window.location.href="http://192.168.3.128:8084/index/fangSession?userId="+userId;
            }else if(data.type==0){
            	
            	if (test!=300){
            		  //没扫码成功，将test+1,达到三百次（150秒），就不扫了。
                    test = test+1;
                    panduan();
                    console.log(test);
            	}
              
            }else if(test==300){
                alert("登录码已失效，请刷新页面更新验证码！");
                $.post("http://192.168.3.128:8084/index/type",{"a":5});
            }
        });
    }
</script>
</body>
</html>